package com.bbx.taxi.client.Bean.Message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.SharedPreUtil;
import com.bbx.api.gclient.GMsg;
import com.bbx.api.gclient.GMsgBroadcastReceiver;
import com.bbx.api.sdk.model.official.passanger.Official_OrderListBuild;
import com.bbx.api.sdk.model.official.passanger.Return.OrderList.OfficialOrderList;
import com.bbx.api.sdk.model.passanger.Token;
import com.bbx.api.sdk.model.passanger.Return.Jmsg.Msgs;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.util.LogUtils;
import com.bbx.api.util.SharedPreEncryptUtil;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
import com.bbx.taxi.client.Activity.MainActivity;
import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
import com.bbx.taxi.client.Activity.Order.OrderEvaluationActivity2;
import com.bbx.taxi.client.Activity.Order.StartServiceActivity;
import com.bbx.taxi.client.Activity.login.LoginActivity;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.DB.JmsgDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
import com.bbx.taxi.client.Listener.MsgBroadcastReceiver;
import com.bbx.taxi.client.MyApplication.OnLocationResultListener;
import com.bbx.taxi.client.Task.MyOrderTask;
import com.bbx.taxi.client.Task.MyOrderTask.OnOrderFinishListener;
import com.bbx.taxi.client.Task.MyOrderTask.OnOrderFinishToMessageListener;
import com.bbx.taxi.client.Util.AppStarted;
import com.bbx.taxi.client.Util.DataCleanManager;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.ToCity;

/**
 * 在线消息
 */
public class Online implements OnOrderFinishToMessageListener{
	public MsgBroadcastReceiver mMsgBroadcastReceiver;
	public Context context;
	public static Map<String, String > map_price=new HashMap<String, String>();
	/** 异常的消息 */
	public ArrayList<ProcessingMessageBean> list_abnormal = new ArrayList<ProcessingMessageBean>();

	public Online() {
		mMsgBroadcastReceiver = new MsgBroadcastReceiver();
	}

	/**
	 * 在线消息
	 */
	public void onOnline(Context context, JSONObject data) {
		this.context = context;
		LogUtils.e("有在线消息进来" + data.toString());
		JSONObject jmsg = null;
		int type = -1;
		try {
			jmsg = data.getJSONObject(GMsg.msg_jmsg);
			type = Integer.parseInt(jmsg.getString(GMsg.msg_type));
			
			//不是传递给本Uid的话，则不存储,不操作
			String cid=data.getString(GMsg.msg_cid);
			Token Mytoken = SharedPreEncryptUtil.getStringEncryptValue(context,
					SharedPreEncryptUtil.TokenAndUid, "");
			String uid = "";
			if (Mytoken != null && !Mytoken.equals(""))
				uid = Mytoken.uid;
			if(!cid.equals(uid)){
				return;
			}
			
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		Msgs.Data msgs_data = null;
		JSONObject jmsg_data = null;
		try {
			jmsg_data = new JSONObject(jmsg.getString(GMsg.msg_data));
			msgs_data = (Msgs.Data) new JsonBuild().getData(Msgs.Data.class,
					jmsg_data.toString());
		} catch (JSONException e) {
			e.printStackTrace();
			// 解析失败则不在进行下去
			return;
		}
		onProcessingMessage(context, type, jmsg_data.toString(), true, data);
		if (msgs_data != null) {
			// 存储在线消息数据
			JmsgDB db_jmsg = new JmsgDB(context);
			String order_id = msgs_data.getOrder_id();
			String time = "";
			try {
				time = DateFormat.getTime(Long.parseLong(jmsg
						.getString(GMsg.msg_time)));
			} catch (Exception e) {
			}
			String json = jmsg.toString();
			db_jmsg.onWrite(order_id, time, type, json);

		}
	}
	public synchronized void onProcessingMessage(final Context context, final int type,
			final String jmsg_data, final boolean isOnline, final JSONObject data) {
		 new Handler(MyApplication.getInstance().getApplicationContext().getMainLooper()).postDelayed(new Runnable() {
			
			@Override
			public void run() {
				onProcessingMessage2(context, type, jmsg_data, isOnline, data);
			}
		}, 1000);
	}
	/**
	 * 处理在线消息跟离线消息
	 */
	public void onProcessingMessage2(Context context, int type,
			String jmsg_data, boolean isOnline, JSONObject data) {
		this.context = context;
		LogUtils.e( "类型为" + type);
		MyOrderingDB db_myordering = new MyOrderingDB(context);// 我的进行中的订单数据库
		MyOrderDB db_myorder = new MyOrderDB(context);// 我的全部订单数据库
		String title = "";
		Msgs.Data msgs_data = (Msgs.Data) new JsonBuild().getData(
				Msgs.Data.class, jmsg_data.toString());
		switch (type) {
		case GMsg.OFFICAIL_ONLINE_PAIDAN:
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int order_status = msgs_data.getOrder_status();
				String driver_id = msgs_data.getDriver_id();
				String driver_name = msgs_data.getDriver_name();
				String car_NO = msgs_data.getCar_NO();
				String driver_phone = msgs_data.getDriver_phone();
				String paidan_vtype=msgs_data.getVType();
				double driver_start = msgs_data.getDriver_star();
				db_myordering.onUpdate(order_id, order_status, driver_id,
						driver_name, car_NO, driver_phone, driver_start);
				db_myorder.onUpdate(order_id, order_status, driver_id,
						driver_name, car_NO, driver_phone, driver_start);
				db_myordering.onUpdateVtype(order_id, paidan_vtype);
				db_myorder.onUpdateVtype(order_id, paidan_vtype);
			}
			onisFindOrdering(db_myordering, type, msgs_data, data, jmsg_data);
			// setTitle(context, type,
			// db_myordering.onReadDB_ing(context,
			// msgs_data.getOrder_id()),msgs_data.getOrder_id());
			// sendBroadcast(context, GMsg.OFFICAIL_ONLINE_PAIDAN, null, jmsg_data);
			break;
		case GMsg.OFFICAIL_ONLINE_CANCEL:
		case GMsg.ONLINE_KF_CANCEL:
			LogUtils.e("", "您有订单被取消");
			// 取消类型
			String cancel_type = "";
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
				cancel_type = msgs_data.getType();
			}
			// 0为客户端取消，则不通知
			if (cancel_type != null && cancel_type.equals("0")) {
			} else {
				onisFindOrdering(db_myordering, type, msgs_data, data,
						jmsg_data);
				// setTitle(context, type,
				// db_myordering.onReadDB_ing(context,
				// msgs_data.getOrder_id()),msgs_data.getOrder_id());
				// sendBroadcast(context, type, data.toString(), jmsg_data);
			}
			break;
		case GMsg.OFFICAIL_ONLINE_GAIPAI:
		case GMsg.ONLINE_KF_GAIPAIL:
			LogUtils.e("", "您有一个订单被改派");
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
			}
			onisFindOrdering(db_myordering, type, msgs_data, data, jmsg_data);
			// setTitle(context, type,
			// db_myordering.onReadDB_ing(context,
			// msgs_data.getOrder_id()),msgs_data.getOrder_id());
			// sendBroadcast(context, type, data.toString(), jmsg_data);
			break;
		case GMsg.ONLINE_RELOGIN:
			// 离线消息不处理登陆问题
			if (!isOnline)
				return;
			title = "您的账号在别的地方登陆";
			LogUtils.e("", "重新登录");
			DataCleanManager.cleanDatabases(context);
			DataCleanManager.cleanSharedPreference(context);
			DataCleanManager.cleanFiles(context);
			DataCleanManager.cleanExternalCache(context);
			sendBroadcast(context, GMsg.ONLINE_RELOGIN, null, jmsg_data);
			showNotification(context, title, type, null,false);
			break;
		case GMsg.OFFICAIL_ONLINE_ONCAR:
			title = "已上车";
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
			}
			onisFindOrdering(db_myordering, type, msgs_data, data, jmsg_data);
			// setTitle(context, type,
			// db_myordering.onReadDB_ing(context,
			// msgs_data.getOrder_id()),msgs_data.getOrder_id());
			// sendBroadcast(context, GMsg.ONLINE_ONCAR, data.toString(),
			// jmsg_data);
			break;
		case GMsg.OFFICAIL_ONLINE_OFFCAR:
			title = "已下车";
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
//				int Order_status = msgs_data.getOrder_status();
				//暂时不根据后台返回的订单类型
				int Order_status = Value.ORDER_STATUS_OFFCAR;
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
			}
			onisFindOrder(db_myorder, type, msgs_data, data, jmsg_data);
			// setTitle(context, type,
			// db_myorder.onReadDB(context,
			// msgs_data.getOrder_id()),msgs_data.getOrder_id());
			// sendBroadcast(context, GMsg.ONLINE_OFFCAR, data.toString(),
			// jmsg_data);
			break;
		case GMsg.ONLINE_FINISH:
		case GMsg.OFFICAIL_ONLINE_FINISH:
			title = "您的一笔订单完成";
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
			}
			// 暂时不需要通知跟消息列表，下次打开的时候记得去消息列表打开消息存储
			// setTitle(context, type,
			// db_myorder.onReadDB(context,
			// msgs_data.getOrder_id()),msgs_data.getOrder_id());
			sendBroadcast(context,type, data.toString(),
					jmsg_data);
			if (OrderEvaluationActivity2.jmsg_data != null) {
				OrderEvaluationActivity2.jmsg_data = jmsg_data;
			}
			break;
		case GMsg.ONLINE_BUSY:
//			if (msgs_data != null) {
//				String order_id = msgs_data.getOrder_id();
//				int Order_status = msgs_data.getOrder_status();
//				db_myordering.onUpdate(order_id, Order_status);
//				db_myorder.onUpdate(order_id, Order_status);
//				title = msgs_data.getText();
//			}
//			showNotification(context, title, type, msgs_data.getOrder_id(),false);
//			sendBroadcast(context, GMsg.ONLINE_BUSY, data.toString(), jmsg_data);
			break;
		case GMsg.ONLINE_BG_ORDER:
			title = "已提交成功";
			// 下单类型,0为APP下单，则不刷新订单列表
			String xiadan_type = "";
			if (msgs_data != null) {
				String order_id = msgs_data.getOrder_id();
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(order_id, Order_status);
				db_myorder.onUpdate(order_id, Order_status);
				xiadan_type = msgs_data.getType();
			}
			if (xiadan_type != null && xiadan_type.equals("0")) {
				setTitle(
						context,
						type,
						db_myordering.onReadDB_ing(context,
								msgs_data.getOrder_id()),
						msgs_data.getOrder_id());
			} else {
				onisFindOrdering(db_myordering, type, msgs_data, data,
						jmsg_data);
				// MyOrderingTask.getInstance(context).setOnOrderingFinishListener(this);
				// MyOrderTask.getInstance(context);
			}

			break;
		case GMsg.ONLINE_KF_CHANGE:
			showNotification(context, context.getString(R.string.msg_change),
					type, msgs_data.getOrder_id(),false);
			sendBroadcast(context, GMsg.ONLINE_KF_CHANGE, data.toString(),
					jmsg_data);
			break;
		case GMsg.ONLINE_NEW_UNPROCESSED:
			showNotification(context, context.getString(R.string.msg_new_unprocessed),
					type, msgs_data.getOrder_id(),true);
			sendBroadcast(context,type, data.toString(),
					jmsg_data);
			break;
		case GMsg.ONLINE_UNPROCESSED_RESULT:
			String result = "";
			String order_id="";
			if (msgs_data != null) {
				 order_id = msgs_data.getOrder_id();
				 result=msgs_data.getResult();
			}
			if(result.equals(Value.MSG_RESULT_PASS)){
				db_myordering.onUpdate(order_id, Value.STATUS_AUDIT_PASS);
				db_myorder.onUpdate(order_id, Value.STATUS_AUDIT_PASS);
				showNotification(context, context.getString(R.string.msg_unprocessed_pass),
						type, msgs_data.getOrder_id(),false);
			}else if(result.equals(Value.MSG_RESULT_NOPASS)){
				db_myordering.onUpdate(order_id, Value.STATUS_AUDIT_NOPASS);
				db_myorder.onUpdate(order_id, Value.STATUS_AUDIT_NOPASS);
				showNotification(context, context.getString(R.string.msg_unprocessed_nopass),
						type, msgs_data.getOrder_id(),false);
			}	
			MyOrderTask.getInstance(context,MyOrderActivity.num_ing,Value.TYPE_ING,Value.OWNALL,MyOrderTask.TYPE_REFRESH);
			sendBroadcast(context,type, data.toString(),
					jmsg_data);
			break;
	    //到达
		case GMsg.OFFICAIL_ONLINE_ARRIVE:
			if (msgs_data != null) {
				int Order_status = msgs_data.getOrder_status();
				db_myordering.onUpdate(msgs_data.getOrder_id(), Order_status);
				db_myorder.onUpdate(msgs_data.getOrder_id(), Order_status);
			}
			sendBroadcast(context,type, data.toString(),
					jmsg_data);
			break;
			//价格更新，只用于订单地图,主要消息列表不能存储。
		case GMsg.OFFICAIL_ONLINE_PRICE:
//			sendBroadcast(context,type, data.toString(),
//					jmsg_data);
			if (msgs_data != null) {
				map_price.put(msgs_data.getOrder_id(), jmsg_data.toString());
			}
		
			break;
	     //更改往返
		case GMsg.OFFICAIL_ONLINE_ROUND_TRIP:
			if (msgs_data != null) {
				String round_trip=msgs_data.getRound_trip();
				db_myordering.onUpdateRound_trip(msgs_data.getOrder_id(), round_trip);
				db_myorder.onUpdateRound_trip(msgs_data.getOrder_id(), round_trip);
			}
			showNotification(context,String.format(context.getString(R.string.msg_round_trip), msgs_data.getRound_trip().equals(Value.ROUND_TRIP)?
					context.getString(R.string.text_round_trip):context.getString(R.string.text_round_trip_no)),
					type, msgs_data.getOrder_id(),true);
			sendBroadcast(context,type, data.toString(),
					jmsg_data);
			break;
	     //被AA的消息
		case GMsg.OFFICAIL_AA:
			sendBroadcast(context,type, data.toString(), jmsg_data);
			break;
		}

	}

	public void setTitle(Context context, int type, OfficialOrderList mOfficialOrderList,
			String order_id) {
		if(mOfficialOrderList!=null&&mOfficialOrderList.getAppoint_time()!=null&&!mOfficialOrderList.getAppoint_time().equals(""))
		{
		String start_city = "";
		String end_city = "";
		try {

			 start_city = ToCity.getCity(mOfficialOrderList
					.getOrderDetail().getStart().getAddress());
			 end_city = ToCity.getCity(mOfficialOrderList
					.getOrderDetail().getEnd().getAddress());
		} catch (Exception e) {
		}
		String title = "";
		switch (type) {
		case GMsg.ONLINE_BG_ORDER:
			title = context.getString(R.string.msg_xiadan);
			break;
		case GMsg.OFFICAIL_ONLINE_PAIDAN:
			title = DateFormat.onCNDateRemove_yyss(mOfficialOrderList
					.getAppoint_time())
					+ ""
					+ start_city
					+ "至"
					+ end_city
					+ "的订单已派发";
			break;
		case GMsg.OFFICAIL_ONLINE_CANCEL:
		case GMsg.ONLINE_KF_CANCEL:
			title = DateFormat.onCNDateRemove_yyss(mOfficialOrderList
					.getAppoint_time())
					+ ""
					+ start_city
					+ "至"
					+ end_city
					+ "的订单被取消";
			break;
		case GMsg.OFFICAIL_ONLINE_GAIPAI:
		case GMsg.ONLINE_KF_GAIPAIL:
			title = DateFormat.onCNDateRemove_yyss(mOfficialOrderList
					.getAppoint_time())
					+ ""
					+ start_city
					+ "至"
					+ end_city
					+ "的订单被改派";
			break;
		case GMsg.OFFICAIL_ONLINE_ONCAR:
			title = context.getString(R.string.msg_oncar);
			break;
		case GMsg.OFFICAIL_ONLINE_OFFCAR:
			title = context.getString(R.string.msg_offcar);
			break;
		case GMsg.ONLINE_FINISH:
		case GMsg.OFFICAIL_ONLINE_FINISH:
			title = DateFormat.onCNDateRemove_yyss(mOfficialOrderList
					.getAppoint_time())
					+ ""
					+ start_city
					+ "至"
					+ end_city
					+ "的订单已完成";
			break;
		}
	    	showNotification(context, title, type, order_id,false);
		}
	}

	public void showNotification(Context context, String title, int type,
			String order_id,boolean isUnprocessed) {
		if (title.equals(""))
			return;
		Intent i;
		switch (type) {
		case GMsg.ONLINE_RELOGIN:
			i = new Intent(context, MainActivity.class);
			break;
		default:
			i = new Intent(context, MainActivity.class).putExtra(
					MainMsg.extra_notification, MainMsg.NOTIFICATION_MAIN)
					.putExtra(MainMsg.extra_notification_orderid, order_id)
					.putExtra(MainMsg.extra_notification_isunprocessed, isUnprocessed);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 注意本行的FLAG设置
			break;
		}

		int ico = R.drawable.icon_pt;
		// FLAG_UPDATE_CURRENT
		// 更新数据，如果有多个PendingIntent，且requestCode相同，则会替换为最新extra数据
		PendingIntent pending = PendingIntent.getActivity(context, 0, i,
				PendingIntent.FLAG_UPDATE_CURRENT);
		// 通知栏
		CharSequence tishi = "帮邦行:" + title;
		long when = DateFormat.getTime(); // 获取当前时间
		Notification notification = new Notification(ico, tishi, when);
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		notification.defaults = Notification.DEFAULT_SOUND;
		// 状态栏
		notification.setLatestEventInfo(context, "帮邦行", title, pending);

		// 状态栏管理器（通知栏管理器）
		NotificationManager notificationmanager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);// 获取通知栏管理器
		notificationmanager.notify(3, notification);
	}

	/**
	 * 发送广播
	 */
	public void sendBroadcast(Context context, int type, String jb,
			String jmsg_data) {
		// 发送广播
		Intent intent = new Intent();
		intent.setAction(MsgBroadcastReceiver.TAG);
		intent.putExtra(MsgBroadcastReceiver.MSG_JSON, jb);
		intent.putExtra(MsgBroadcastReceiver.MSG_TYPE, type);
		intent.putExtra(MsgBroadcastReceiver.MSG_DATA, jmsg_data);
		context.sendBroadcast(intent);
	}

	/**
	 * 注册广播
	 */
	public void registerReceiver(Context context) {
		// 注册广播
		IntentFilter filter = new IntentFilter();
		filter.addAction(MsgBroadcastReceiver.TAG);
		filter.setPriority(Integer.MAX_VALUE);
		context.registerReceiver(mMsgBroadcastReceiver, filter);
	}

	public void unregisterReceiver(Context context) {
		context.unregisterReceiver(mMsgBroadcastReceiver);
	}

	/**
	 * 判断进行中订单是否存在，不存在则加载订单
	 */
	private void onisFindOrdering(final MyOrderingDB db_myordering, final int type,
			final Msgs.Data msgs_data, final JSONObject data, final String jmsg_data) {
		        new AsyncTask<Void, Void, Void>() {
		        	OfficialOrderList mOfficialOrderList;
					@Override
					protected Void doInBackground(Void... arg0) {
		        		mOfficialOrderList = db_myordering.onReadDB_ing(context,
								msgs_data.getOrder_id());
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						// 找不到该订单
						if (mOfficialOrderList == null) {
							LogUtils.e("","找不到订单");
							MyOrderTask.getInstance(context,MyOrderActivity.num_all2,type, jmsg_data,data,Value.TYPE_ING,Value.OWNALL,MyOrderTask.TYPE_REFRESH).setOnOrderFinishToMessageListener(Online.this);
						}else{
							setTitle(context, type, mOfficialOrderList, msgs_data.getOrder_id());
							sendBroadcast(context, type, data.toString(), jmsg_data);
						} 
						super.onPostExecute(result);
					}
					
		        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


	}

	/**
	 * 判断订单是否存在，不存在则加载订单
	 */
	private void onisFindOrder(final MyOrderDB db_myorder, final int type,
			final Msgs.Data msgs_data, final JSONObject data, final String jmsg_data) {
        new AsyncTask<Void, Void, Void>() {
        	OfficialOrderList mOfficialOrderList;
				@Override
				protected Void doInBackground(Void... arg0) {
					mOfficialOrderList = db_myorder.onReadDB(context,
							msgs_data.getOrder_id());
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					// 找不到该订单
					if (mOfficialOrderList == null) {
						MyOrderTask.getInstance(context,MyOrderActivity.num_all2,type, jmsg_data,data,Value.TYPE_ALL,Value.OWNALL,MyOrderTask.TYPE_REFRESH).setOnOrderFinishToMessageListener(Online.this);
					} else {
						setTitle(context, type, mOfficialOrderList, msgs_data.getOrder_id());
						sendBroadcast(context, type, data.toString(), jmsg_data);
					}
					super.onPostExecute(result);
				}
				
	        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	@Override
	public void onOrderFinishToMessage(int flag,int own_expense,ArrayList<OfficialOrderList> list,final int type,final String jmsg_data,final JSONObject data) {
		switch(flag){
		case Value.TYPE_ING:
			if(list!=null&&jmsg_data!=null){
				final Msgs.Data msgs_data = (Msgs.Data) new JsonBuild().getData(
						Msgs.Data.class, jmsg_data.toString());
				new AsyncTask<Void, Void, Void>() {
					OfficialOrderList mOfficialOrderList;
					@Override
					protected Void doInBackground(Void... arg0) {
						MyOrderingDB db_myordering = new MyOrderingDB(context);// 我的全部订单数据库
						mOfficialOrderList = db_myordering.onReadDB_ing(context,
								msgs_data.getOrder_id());
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						setTitle(context, type, mOfficialOrderList, msgs_data.getOrder_id());
						sendBroadcast(context, type, data.toString(), jmsg_data);
						super.onPostExecute(result);
					}
				  	
				}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			}
			
			break;
		case Value.TYPE_ALL:
			if(list!=null&&jmsg_data!=null){
				final Msgs.Data msgs_data = (Msgs.Data) new JsonBuild().getData(
						Msgs.Data.class, jmsg_data.toString());
				new AsyncTask<Void, Void, Void>() {
					OfficialOrderList mOfficialOrderList;
					@Override
					protected Void doInBackground(Void... arg0) {
						MyOrderingDB db_myordering = new MyOrderingDB(context);// 我的全部订单数据库
						mOfficialOrderList = db_myordering.onReadDB_ing(context,
								msgs_data.getOrder_id());
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						setTitle(context, type, mOfficialOrderList, msgs_data.getOrder_id());
						sendBroadcast(context, type, data.toString(), jmsg_data);
						super.onPostExecute(result);
					}
				  	
				}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			}
			break;
		}
		
		
	}
}
